﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using NutriLeaf.Web.Model;

namespace NutriLeaf.Services.Core.Article
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Articles" in code, svc and config file together.
    public class Articles : IArticleService
    {
        public void InsertArticle(NutriLeaf.Web.Model.Article article)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.InsertArticle(article, ref context);
            
        }

        public void InsertArticleByDetails(string articleTitle, string articleDescription, string articleText, int userId, int categoryId, bool IsApproved)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.InsertArticle(articleTitle, articleDescription, articleText, userId, categoryId, IsApproved, ref context);
        }

        public void ApproveArticleById(int articleId)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.ApproveArticle(articleId, ref context);
        }

        public void ApproveArticle(NutriLeaf.Web.Model.Article article)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.ApproveArticle(article, ref context);
        }

        public bool IsApproved(int articleId)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            return NutriLeaf.Web.Core.Articles.Article.IsApproved(articleId, ref context);
          
        }

        public void UpdateArticle(NutriLeaf.Web.Model.Article article)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.UpdateArticle(article, ref context);
        }

        public List<NutriLeaf.Web.Model.Article> GetArticlesWrittenByUser(int userId)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            return NutriLeaf.Web.Core.Articles.Article.GetArticlesWrittenByUser(userId, ref context);
        }

        public List<NutriLeaf.Web.Model.Article> GetArticlesByCategory(ArticleCategory category)
        {

            NutriLeafDBEntities context = new NutriLeafDBEntities();
            return NutriLeaf.Web.Core.Articles.Article.GetArticlesByCategory(category, ref context);
        }

        public List<NutriLeaf.Web.Model.Article> GetArticleByCategoryById(int categoryId)
        {

            NutriLeafDBEntities context = new NutriLeafDBEntities();
            return NutriLeaf.Web.Core.Articles.Article.GetArticleByCategory(categoryId, ref context);
        }

        public void InsertCategoryByCategory(ArticleCategory category)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.InsertCategory(category, ref context);
        }

        public void InsertCategory(string categoryName, string categoryDescription, int ParentCategoryID)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.InsertCategory(categoryName, categoryDescription, ParentCategoryID, ref context);
        }

        public void RemoveCategoryById(int categoryId)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.RemoveCategory(categoryId, ref context);
        }

        public void RemoveCategory(ArticleCategory category)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.RemoveCategory(category, ref context);
        }

        public void UpdateCateogory(ArticleCategory category)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.UpdateCateogory(category, ref context);
        }

        public void LikeArticleById(int articleId, int userId, bool like)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.LikeArticle(articleId, userId, like, ref context);
        }

        public void LikeArticle(NutriLeaf.Web.Model.Article article, User user, bool like)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.LikeArticle(article, user, like, ref context);
        }

        public void RemoveArticleLikeById(int likeId)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.RemoveArticleLike(likeId, ref context);
        }

        public void RemoveArticleLike(ArticleLike like)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            NutriLeaf.Web.Core.Articles.Article.RemoveArticleLike(like, ref context);
        }

        public List<NutriLeaf.Web.Model.Article> GetArticlesLikedByUser(int userId)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            return NutriLeaf.Web.Core.Articles.Article.GetArticlesLikedByUser(userId, ref context);
        }

        public List<NutriLeaf.Web.Model.Article> GetMostPopularArticles(int count)
        {
            NutriLeafDBEntities context = new NutriLeafDBEntities();
            return NutriLeaf.Web.Core.Articles.Article.GetMostPopularArticles(count, ref context);
        }
    }
}
